const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const { Op } = require('sequelize');

const CampusAccount = sequelize.define('CampusAccount', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true
  },
  user_id: {
    type: DataTypes.UUID,
    allowNull: false,
    comment: '用户ID'
  },
  account_type: {
    type: DataTypes.ENUM('teacher', 'student'),
    allowNull: false,
    comment: '账户类型'
  },
  employee_id: {
    type: DataTypes.STRING,
    comment: '员工ID'
  },
  department: {
    type: DataTypes.STRING,
    comment: '部门'
  },
  status: {
    type: DataTypes.ENUM('active', 'inactive', 'graduated'),
    defaultValue: 'active',
    comment: '账户状态'
  },
  grade: {
    type: DataTypes.STRING,
    comment: '年级'
  },
  class: {
    type: DataTypes.STRING,
    comment: '班级'
  },
  major: {
    type: DataTypes.STRING,
    comment: '专业'
  },
  admission_year: {
    type: DataTypes.INTEGER,
    comment: '入学年份'
  },
  graduation_year: {
    type: DataTypes.INTEGER,
    comment: '毕业年份'
  },
  academic_status: {
    type: DataTypes.ENUM('normal', 'probation', 'suspended'),
    defaultValue: 'normal',
    comment: '学术状态'
  },
  metadata: {
    type: DataTypes.JSON,
    defaultValue: {},
    comment: '元数据'
  }
}, {
  underscored: true,
  indexes: [
    {
      unique: true,
      fields: ['employee_id'],
      where: {
        employee_id: {
          [Op.ne]: null
        }
      }
    }
  ]
}, {
  comment: '校园账户信息表'
});

module.exports = CampusAccount; 